import java.io.*;

/**
 * @author ml
 * @create 2017-08-21--16:47
 */
public class PFFrame_Pro {

    private String basePath;
    private String serverIp;

    public PFFrame_Pro(String basePath,String serverIp){
        this.basePath=basePath;
        this.serverIp=serverIp;

    }

    public void readFile() throws IOException {
        InputStream is=new FileInputStream(basePath+FilePathEnum.PFFRAME_PRO.getValue());

        BufferedReader reader=new BufferedReader(new InputStreamReader(is,"utf-8"));

        String temp=null;

        StringBuffer resultStr=new StringBuffer();

        while((temp=reader.readLine())!=null){
            resultStr.append(temp).append("\r\n");

        }
        reader.close();
        System.out.println("resultStr:"+resultStr);

        String afterStr=resultStr.toString().replaceAll("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",serverIp);

        System.out.println("afterStr:"+afterStr);

        //写入文件
        writeFile(afterStr);

    }

    private void writeFile(String afterStr) throws IOException {

        File targetFile=new File(basePath+FilePathEnum.PFFRAME_PRO.getValue());

        InputStream is=new ByteArrayInputStream(afterStr.getBytes());

        FileOutputStream output=new FileOutputStream(targetFile);

        int i=0;
        byte[] temp=new byte[1024];
        while((i=is.read(temp))!=-1){
            output.write(temp,0,i);

        }
        output.close();
    }

}
